package main

import (
	"fmt"
	"path/filepath"

	"demserver/src/elevation"
)

func main() {
	// Use the test GeoTIFF file
	testFile := "test_dem.tiff"
	
	// Get absolute path to the test file
	absPath, err := filepath.Abs(testFile)
	if err != nil {
		fmt.Printf("Failed to get absolute path: %v\n", err)
		return
	}

	fmt.Printf("Loading test GeoTIFF file: %s\n", absPath)
	geoTiff, err := elevation.LoadGeoTIFF(absPath)
	if err != nil {
		fmt.Printf("Failed to load GeoTIFF: %v\n", err)
		return
	}
	fmt.Println("GeoTIFF loaded successfully")
	fmt.Printf("Image dimensions: %dx%d\n", geoTiff.Width, geoTiff.Height)

	// Test coordinate conversion at different points
	testPoints := [][2]float64{
		{0, 0},
		{50, 50},
		{99, 99},
	}

	for _, point := range testPoints {
		lat, lon := point[0], point[1]
		x, y, err := geoTiff.LatLonToPixel(lat, lon)
		if err != nil {
			fmt.Printf("Failed to convert coordinates (%f, %f): %v\n", lat, lon, err)
			continue
		}
		fmt.Printf("Pixel coordinates for (%f, %f): (%f, %f)\n", lat, lon, x, y)

		// Test elevation retrieval
		elevationVal, err := geoTiff.GetElevation(x, y)
		if err != nil {
			fmt.Printf("Failed to get elevation at (%f, %f): %v\n", x, y, err)
			continue
		}
		fmt.Printf("Elevation at (%f, %f): %f\n", x, y, elevationVal)
	}

	// Test out of bounds
	fmt.Println("\nTesting out of bounds coordinates:")
	_, err = geoTiff.GetElevation(-1, -1)
	if err != nil {
		fmt.Printf("Expected error for out of bounds coordinates: %v\n", err)
	}
}
